package com.b2b.controller;


import com.b2b.model.common.ResponseBean;
import com.b2b.model.entity.ReceivingInfo;
import com.b2b.service.ReceivingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/receiving")
@PropertySource("classpath:config.properties")
public class ReceivingController {

    @Value("${refreshTokenExpireTime}")
    private String refreshTokenExpireTime;


    @Autowired
    private ReceivingInfoService receivingService;

    @PostMapping("/add")
    public ResponseBean add(@RequestBody ReceivingInfo receiving){
        receivingService.insert(receiving);
        return new ResponseBean(HttpStatus.OK.value(), "添加成功", null);
    }

    @DeleteMapping("/delete")
    public ResponseBean delete(@RequestParam Integer receivingInfoId){
        receivingService.deleteByPrimaryKey(receivingInfoId);
        return new ResponseBean(HttpStatus.OK.value(), "刪除成功", null);
    }

    @PutMapping("/update")
    public ResponseBean update(@RequestBody ReceivingInfo receiving){
        receivingService.updateByPrimaryKeySelective(receiving);
        return new ResponseBean(HttpStatus.OK.value(), "修改成功", null);
    }

    @GetMapping("/getMy")
    public ResponseBean getMy(@RequestParam Integer companyId){
        ReceivingInfo receiving = new ReceivingInfo();
        receiving.setCompanyId(companyId);
        return new ResponseBean(HttpStatus.OK.value(), "查询成功", receivingService.select(receiving));
    }

    @GetMapping("/getDetail")
    public ResponseBean getDetail(@RequestParam Integer receivingId){
        return new ResponseBean(HttpStatus.OK.value(), "查询成功", receivingService.selectByPrimaryKey(receivingId));
    }



}
